package com.java3_14;

import java.util.Arrays;
import java.util.Objects;

public class Student implements Cloneable{
    private String name;
    private int age;

    private int[] date;
    public Student(){

    }

    public Student(String name, int age, int[] date) {
        this.name = name;
        this.age = age;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int[] getDate() {
        return date;
    }

    public void setDate(int[] date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", date=" + Arrays.toString(date) +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //获取当前对象的数组
        int[] arr = this.date;
        //创建一个等长的空数组
        int[] arrNew = new int[arr.length];
        //一个一个元素数据进行复制
        for (int i = 0; i < arr.length; i++) {
            arrNew[i] = arr[i];
        }
        //进行浅克隆创建对象
        Student clone = (Student) super.clone();
        //更换里面的数组
        clone.date = arrNew;
        //返回对象
        return clone;
    }

    //在数据进行回收是可以做些事情
    @Override
    protected void finalize() throws Throwable {
        System.out.println("数据已经被回收");
    }
}
